package com.hulytu.dev2.droid.util;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

public class Utils {


    /**
     * @param ctx
     * @return
     * @since 1.0.2
     */
    public static boolean isUiProcess(Context ctx) {
        int pid = android.os.Process.myPid();

        ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
        if (processes == null || processes.isEmpty()) return false;

        for (ActivityManager.RunningAppProcessInfo process : processes) {
            if (process.pid == pid) {
                return ctx.getPackageName().equals(process.processName);
            }
        }

        return false;
    }


}
